<!-- 
 * @Author: guanpf 992093924@qq.om
 * @Date: 2023-07-24 16:44:40
 * @LastEditTime: 2023-10-14 17:54:38
 * @LastEditors: guanpf
 * @Description: 
 * @FilePath: /ZCGL_WX/src/views/main/asset/views/inventory.vue
 -->
<template>
  <div class="inventory">
    <div class="top-search">
      <CommonSearch placeholder="请输入关键词搜索" @searchFun="searchFun"></CommonSearch>
    </div>
    <div class="count">共计{{ count }}条结果</div>

    <div class="list">
      <template v-if="list.length > 0">
        <div class="item" v-for="(item, index) in list" :key="index" @click="toLog(item)">
          <div class="label">
            <span class="title">盘点标题</span>
            <span class="name">{{ item.checkTitle }}</span>
          </div>
          <div class="label">
            <span class="title">创建人</span>
            <span class="name">{{ item.createByName ||  item.createBy}}</span>
          </div>
          <div class="label">
            <span class="title">盘点人</span>
            <span class="name">{{ item.checkUserName || item.checkUser}}</span>
          </div>
          <div class="label">
            <span class="title">创建时间</span>
            <span class="name">{{ item.createTime }}</span>
          </div>
          <div
            :class="item.unreadCount == 0 ? 'status status-finish' : 'status status-unfinish'"
          >
            {{ item.unreadCount == 0 ? "已完成" : "未完成" }}
          </div>
        </div>
      </template>
      <template v-else>
        <no-data></no-data>
      </template>
    </div>

    <div class="submit-box">
      <x-button class="submit-btn" @click.native="createInventory">创建资产盘点</x-button>
    </div>
  </div>
</template>

<script>
import CommonSearch from "../components/search";
import AssetApi from "@/api/asset.js";
import { XButton } from "vux";
export default {
  components: { CommonSearch, XButton },
  data() {
    return {
      name: "",
      count: 0,
      list: [],
      all:false // 是否展示全部数据
    };
  },
  mounted() {
    if(this.$route.query.all)this.all = true
    this.getList();
  },
  methods: {
    getList() {
      let _params = {
        pageNum: 1,
        pageSize: 1000,
        key: this.name,
        userId: this.all ? undefined : this.$store.state.user.userInfo.wxUserId,
      };
      AssetApi.assetCheckAll(_params).then((res) => {
        if (res.code == "0000") {
          this.list = res.data.records;
          this.count = res.data.total;
        }
      });
    },
    searchFun(name) {
      this.name = name;
      this.getList()
      // 根据名称执行搜索操作
    },
    toLog(item) {
      // if (item.unreadCount > 0) {
        this.$router.push({ name: 'inventoryDetail', params:item});
      // }
    },
    createInventory() {
      if(this.all){
        this.$router.push({
          path: "allInventory",
        });

      }else{
        this.$router.push({
          path: "assetOpt",
          query: {
            type: "inventory",
          },
        });

      }

    },
  },
};
</script>

<style lang="less" scoped>
.top-search {
  padding: 10px 0;
}
.count {
  margin: 10px 20px;
}
.list {
  height: auto;
  background: #f1f1f1;
  padding: 10px;
  .item {
    padding: 10px 15px;
    border-radius: 8px;
    background: #fff;
    margin-bottom: 10px;
    position: relative;

    .label {
      display: flex;
      justify-content: flex-start;
      height: 30px;
      line-height: 30px;
      color: rgb(127, 127, 127);

      .title {
        display: inline-block;
        width: 100px;
      }
    }
  }
}
.status {
  color: #fff;
  border-radius: 2px;
  width: 60px;
  height: 24px;
  font-size: 12px;
  line-height: 24px;
  text-align: center;
  position: absolute;
  right: 10px;
  top: 40px;
  transform: rotate(-20deg);
}
.status-finish {
  background: rgb(101, 170, 29);
}
.status-unfinish {
  background: rgb(160, 159, 160);
}
.submit-box {
  position: fixed;
  bottom: 0;
  width: 100%;
  padding: 10px 0;
  background: #fff;
  z-index: 100;
  .submit-btn {
    width: 260px;
    border-radius: 20px;
    color: #fff;
    margin: 0 auto;
    border-color: rgb(205, 166, 105);
    background: rgb(205, 166, 105);
  }
}
.inventory {
  background: #fff;
  padding-bottom: 80px;
}
</style>
